package com.gujiangbo.observable;

import java.util.concurrent.TimeUnit;

public class ObservableTest {

    public static void main(String[] args) {

        final TaskLifecycle<String> lifecycle = new TaskLifecycle.EmptyLifecycle<String>() {

            @Override
            public void onStart(Thread thread) {
                System.out.println(thread.getName() + " is on start.");
            }

            @Override
            public void onRunning(Thread thread) {
                System.out.println(thread.getName() + " is running ....");
            }

            @Override
            public void onFinish(Thread thread, String result) {
                System.out.println(thread.getName() + " was finished. the result is " + result);
            }

            @Override
            public void onError(Thread thread, Exception e) {
                System.out.println(thread.getName() + " is error" + e.getMessage());
            }
        };
        ObservableThread ob = new ObservableThread<>(lifecycle, () -> {

            try {
                TimeUnit.SECONDS.sleep(3);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
            System.out.println(Thread.currentThread().getName() + " finished done.");
            return " Hello Observer";
        });
        ob.start();


    }
}
